//
//  UIBarButtonItem + Extension.swift
//  HDBWeibo
//
//  Created by leidon on 2016/11/22.
//  Copyright © 2016年 BONC. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    /// 创建UIBarButtonItem,使用自定义的按钮，解决系统自带的点击不能高亮问题
    ///
    /// - parameter title:  title
    /// - parameter font:   font
    /// - parameter target: target
    /// - parameter action: action
    ///
    /// - returns: UIBarButtonItem
    convenience init(title : String, font : CGFloat = 16, target : AnyObject, action : Selector, isBack : Bool = false) {
        
        let barBtn : UIButton = UIButton.cz_textButton(title, fontSize: font, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        //当是左返回按钮的时候，添加返回的 <返回 箭头图标
        if isBack {
            barBtn.setImage(UIImage(named:"navigationbar_back_withtext"), for: UIControlState.init(rawValue: 0))
            barBtn.setImage(UIImage(named:"navigationbar_back_withtext_highlighted"), for: UIControlState.highlighted)
            barBtn.sizeToFit()
        }
        
        barBtn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        self.init(customView: barBtn)
    }
}
